define("scriptFilters",["lib/utils/filter_builder"],function (filterBuilder) {


    var cacheFilter =function(originalFunc){

        return function() {
            var key = arguments[0];
            var script = $sys.getBean("script", key);
            if (isNull(script)) {
                script = originalFunc.apply(this, arguments);
                $sys.setBean(this["scriptType"] , key, script);
            }
            return script;
        }
    }

    var objFilter =function(originalFunc){
        var filters = $sys.getBean("script", "filters");
        DEBUG(__DIR__+"["+filters+"]")
        filterBuilder.filters = filters;
        return function() {
            var name = arguments[0];
            var script = originalFunc.apply(this, arguments);
            if (!isNull(filters)) {
                script = filterBuilder.createProxy(name,script,"script");
            }
            return script;
        }
    }

    var mFilter = {
        matchName:/M/,
        matchMethod:/require/,
        matchType:/.*/,
        list:[cacheFilter]
    };
    var objFilter = {
        matchName:/M/,
        matchMethod:/define/,
        matchType:/.*/,
        list:[objFilter]
    };
    return [objFilter, mFilter];
});